package org.example.common.log.event;

import cn.hutool.core.bean.BeanUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.example.api.system.RemoteOperatorLogService;
import org.example.api.system.domain.bo.RemoteOperatorLogBo;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * 异步调用日志服务
 *
 */
@Component
@Slf4j
public class LogEventListener {

    @DubboReference
    private RemoteOperatorLogService remoteLogService;

    /**
     * 保存系统日志记录
     */
    @Async
    @EventListener
    public void saveLog(OperatorLogEvent operatorLogEvent) {
        RemoteOperatorLogBo sysOperatorLog = BeanUtil.toBean(operatorLogEvent, RemoteOperatorLogBo.class);
        remoteLogService.saveLog(sysOperatorLog);
    }


}
